VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.ocx"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Object = "{B3FB64BF-91F9-11D7-A482-0008A14158BC}#2.22#0"; "ITGControls.ocx"
Begin VB.Form frmMFGProductionOrder 
   BackColor       =   &H00F7D9C2&
   BorderStyle     =   0  'None
   Caption         =   "Form1"
   ClientHeight    =   8190
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   11550
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   ScaleHeight     =   8190
   ScaleWidth      =   11550
   ShowInTaskbar   =   0   'False
   Begin ITGControls.ITGTab SSTab1 
      Height          =   1980
      Left            =   -15
      TabIndex        =   8
      Top             =   0
      Width           =   10515
      _ExtentX        =   18547
      _ExtentY        =   3493
      TabCount        =   2
      TabCaption(0)   =   "               Main               "
      TabContCtrlCnt(0)=   1
      Tab(0)ContCtrlCap(1)=   "ComunionFrames1"
      TabCaption(1)   =   "               List               "
      TabContCtrlCnt(1)=   1
      Tab(1)ContCtrlCap(1)=   "dtgList"
      TabTheme        =   2
      ActiveTabBackStartColor=   16250865
      ActiveTabBackEndColor=   16243138
      InActiveTabBackStartColor=   16243138
      InActiveTabBackEndColor=   16243138
      InActiveTabForeColor=   -2147483639
      BeginProperty ActiveTabFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty InActiveTabFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      OuterBorderColor=   4210752
      TopLeftInnerBorderColor=   4210752
      BottomRightInnerBorderColor=   4210752
      DisabledTabBackColor=   16243138
      DisabledTabForeColor=   -2147483627
      Begin MSDataGridLib.DataGrid dtgList 
         Height          =   1665
         Left            =   -74985
         TabIndex        =   12
         Top             =   315
         Width           =   10500
         _ExtentX        =   18521
         _ExtentY        =   2937
         _Version        =   393216
         AllowUpdate     =   0   'False
         AllowArrows     =   -1  'True
         Appearance      =   0
         HeadLines       =   1
         RowHeight       =   15
         TabAction       =   2
         FormatLocked    =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   5
         BeginProperty Column00 
            DataField       =   "cTranNo"
            Caption         =   "Transaction No."
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "dDate"
            Caption         =   "Date"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "MM/dd/yyyy"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   3
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "cType"
            Caption         =   "Type"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "MM/dd/yyyy"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "cRefNo"
            Caption         =   "Reference Number"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "MM/dd/yyyy"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column04 
            DataField       =   "dNeeded"
            Caption         =   "Date Needed"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "MM/dd/yyyy"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   3
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            AllowRowSizing  =   0   'False
            BeginProperty Column00 
               ColumnAllowSizing=   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   2085.166
            EndProperty
            BeginProperty Column01 
               Locked          =   -1  'True
               ColumnWidth     =   1454.74
            EndProperty
            BeginProperty Column02 
               Locked          =   -1  'True
               ColumnWidth     =   1769.953
            EndProperty
            BeginProperty Column03 
               Locked          =   -1  'True
               ColumnWidth     =   2025.071
            EndProperty
            BeginProperty Column04 
               Locked          =   -1  'True
            EndProperty
         EndProperty
      End
      Begin ITGControls.ComunionFrames ComunionFrames1 
         Height          =   1665
         Left            =   15
         Top             =   315
         Width           =   10500
         _ExtentX        =   18521
         _ExtentY        =   2937
         FrameColor      =   4210752
         BackColor       =   16243138
         FillColor       =   16243138
         RoundedCorner   =   0   'False
         Caption         =   "Production Order Information"
         Alignment       =   0
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ThemeColor      =   5
         ColorFrom       =   16243138
         ColorTo         =   16250865
         Begin VB.CommandButton cmdPickSO 
            Height          =   300
            Left            =   2865
            Picture         =   "frmMFGProductionOrder.frx":0000
            Style           =   1  'Graphical
            TabIndex        =   4
            Top             =   855
            Width           =   315
         End
         Begin VB.Timer Timer1 
            Interval        =   300
            Left            =   3180
            Top             =   540
         End
         Begin VB.ComboBox cboType 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   315
            ItemData        =   "frmMFGProductionOrder.frx":014A
            Left            =   7605
            List            =   "frmMFGProductionOrder.frx":0154
            Style           =   2  'Dropdown List
            TabIndex        =   2
            Top             =   540
            Width           =   1305
         End
         Begin ITGControls.ITGTextBox txtTranNo 
            Height          =   285
            Left            =   135
            TabIndex        =   0
            Top             =   540
            Width           =   3045
            _ExtentX        =   5159
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Transaction No."
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1250
            TextBoxWidth    =   1735
            Required        =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtRemarks 
            Height          =   285
            Left            =   135
            TabIndex        =   6
            Top             =   1185
            Width           =   8775
            _ExtentX        =   15266
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Label           =   "Remarks"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1250
            TextBoxWidth    =   7465
            LinkForeColor   =   0
         End
         Begin ITGControls.ITGDateBox dtbDate 
            Height          =   285
            Left            =   4920
            TabIndex        =   1
            Tag             =   "Transaction Date"
            Top             =   540
            Width           =   1305
            _ExtentX        =   2302
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Text            =   ""
            SendKeysTab     =   -1  'True
            Mandatory       =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtRefNo 
            Height          =   285
            Left            =   135
            TabIndex        =   3
            Top             =   870
            Width           =   2700
            _ExtentX        =   4551
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "Reference No."
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1250
            TextBoxWidth    =   1390
            Required        =   -1  'True
            LinkForeColor   =   0
         End
         Begin ITGControls.ITGDateBox dtbNeeded 
            Height          =   285
            Left            =   7605
            TabIndex        =   5
            Tag             =   "Date Needed"
            Top             =   885
            Width           =   1305
            _ExtentX        =   2302
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Text            =   ""
            SendKeysTab     =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtType 
            Height          =   285
            Left            =   6510
            TabIndex        =   9
            Tag             =   "cboType"
            Top             =   555
            Width           =   2145
            _ExtentX        =   3572
            _ExtentY        =   503
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Mandatory       =   -1  'True
            Label           =   "Type"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1100
            TextBoxWidth    =   985
            Required        =   -1  'True
         End
         Begin VB.Label Label1 
            AutoSize        =   -1  'True
            BackStyle       =   0  'Transparent
            Caption         =   "Date Needed"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   195
            Left            =   6555
            TabIndex        =   11
            Top             =   885
            Width           =   945
         End
         Begin VB.Label Label5 
            BackStyle       =   0  'Transparent
            Caption         =   "Date"
            BeginProperty Font 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   345
            Left            =   4350
            TabIndex        =   10
            Top             =   570
            Width           =   720
         End
      End
   End
   Begin MSComctlLib.StatusBar sbRS 
      Align           =   2  'Align Bottom
      Height          =   285
      Left            =   0
      TabIndex        =   7
      Top             =   7905
      Width           =   11550
      _ExtentX        =   20373
      _ExtentY        =   503
      _Version        =   393216
      BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
         NumPanels       =   5
         BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
         BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
         EndProperty
         BeginProperty Panel3 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Alignment       =   1
            AutoSize        =   1
            Bevel           =   0
            Object.Width           =   7146
            MinWidth        =   2
         EndProperty
         BeginProperty Panel4 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
         BeginProperty Panel5 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
   End
   Begin ITGControls.ComunionFrames ComunionFrames4 
      Height          =   1785
      Left            =   0
      Top             =   5655
      Width           =   10515
      _ExtentX        =   18547
      _ExtentY        =   3149
      FrameColor      =   4210752
      BackColor       =   16243138
      FillColor       =   16243138
      RoundedCorner   =   0   'False
      Caption         =   "Procedure"
      Alignment       =   0
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ThemeColor      =   5
      ColorFrom       =   16243138
      ColorTo         =   16250865
      Begin MSDataGridLib.DataGrid dtgSum 
         Height          =   1365
         Left            =   0
         TabIndex        =   13
         Top             =   420
         Width           =   10515
         _ExtentX        =   18547
         _ExtentY        =   2408
         _Version        =   393216
         AllowUpdate     =   -1  'True
         AllowArrows     =   -1  'True
         BackColor       =   16777215
         HeadLines       =   1
         RowHeight       =   15
         TabAcrossSplits =   -1  'True
         TabAction       =   2
         FormatLocked    =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   5
         BeginProperty Column00 
            DataField       =   "cItemNo"
            Caption         =   "Product ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "cDesc"
            Caption         =   "Description"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "cUnit"
            Caption         =   "Unit"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "nAmount"
            Caption         =   "Amount"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column04 
            DataField       =   "cStatus"
            Caption         =   "Status"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "0"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            BeginProperty Column00 
               Locked          =   -1  'True
               ColumnWidth     =   1995.024
            EndProperty
            BeginProperty Column01 
               Locked          =   -1  'True
               ColumnWidth     =   3495.118
            EndProperty
            BeginProperty Column02 
               Locked          =   -1  'True
               Object.Visible         =   0   'False
               ColumnWidth     =   569.764
            EndProperty
            BeginProperty Column03 
               Alignment       =   1
               Locked          =   -1  'True
               Object.Visible         =   0   'False
               ColumnWidth     =   1275.024
            EndProperty
            BeginProperty Column04 
               Alignment       =   1
               Locked          =   -1  'True
               Object.Visible         =   0   'False
               ColumnWidth     =   1289.764
            EndProperty
         EndProperty
      End
   End
   Begin ITGControls.ComunionFrames ComunionFrames3 
      Height          =   1965
      Left            =   0
      Top             =   3705
      Width           =   10515
      _ExtentX        =   18547
      _ExtentY        =   3466
      FrameColor      =   4210752
      BackColor       =   16243138
      FillColor       =   16243138
      RoundedCorner   =   0   'False
      Caption         =   "Bill of Materials"
      Alignment       =   0
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ThemeColor      =   5
      ColorFrom       =   16243138
      ColorTo         =   16250865
      Begin VB.ComboBox cboBM 
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   315
         ItemData        =   "frmMFGProductionOrder.frx":016C
         Left            =   75
         List            =   "frmMFGProductionOrder.frx":0179
         Style           =   2  'Dropdown List
         TabIndex        =   14
         Top             =   1320
         Visible         =   0   'False
         Width           =   1395
      End
      Begin MSDataGridLib.DataGrid dtgBM 
         Height          =   1545
         Left            =   0
         TabIndex        =   15
         Top             =   420
         Width           =   10515
         _ExtentX        =   18547
         _ExtentY        =   2725
         _Version        =   393216
         AllowUpdate     =   -1  'True
         AllowArrows     =   -1  'True
         BackColor       =   16777215
         HeadLines       =   1
         RowHeight       =   15
         TabAcrossSplits =   -1  'True
         TabAction       =   2
         FormatLocked    =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   7
         BeginProperty Column00 
            DataField       =   "cItemNo"
            Caption         =   "Product ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "cDesc"
            Caption         =   "Description"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "cUnit"
            Caption         =   "Unit"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "nSRPrice"
            Caption         =   "SRP"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column04 
            DataField       =   "nQty"
            Caption         =   "Quantity"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column05 
            DataField       =   "cStatus"
            Caption         =   "Status"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column06 
            DataField       =   "cWRRNo"
            Caption         =   "Reference No."
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            BeginProperty Column00 
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   1289.764
            EndProperty
            BeginProperty Column01 
               Locked          =   -1  'True
               ColumnWidth     =   2505.26
            EndProperty
            BeginProperty Column02 
               Locked          =   -1  'True
               ColumnWidth     =   569.764
            EndProperty
            BeginProperty Column03 
               Alignment       =   1
               Locked          =   -1  'True
               ColumnWidth     =   1275.024
            EndProperty
            BeginProperty Column04 
               Alignment       =   1
               ColumnWidth     =   1289.764
            EndProperty
            BeginProperty Column05 
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   1335.118
            EndProperty
            BeginProperty Column06 
               Locked          =   -1  'True
               ColumnWidth     =   1124.787
            EndProperty
         EndProperty
      End
   End
   Begin ITGControls.ComunionFrames ComunionFrames2 
      Height          =   1755
      Left            =   0
      Top             =   1965
      Width           =   10515
      _ExtentX        =   18547
      _ExtentY        =   3096
      FrameColor      =   4210752
      BackColor       =   16243138
      FillColor       =   16243138
      RoundedCorner   =   0   'False
      Caption         =   "For Production"
      Alignment       =   0
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ThemeColor      =   5
      ColorFrom       =   16243138
      ColorTo         =   16250865
      Begin MSDataGridLib.DataGrid dtgFG 
         Height          =   1320
         Left            =   0
         TabIndex        =   16
         Top             =   420
         Width           =   10515
         _ExtentX        =   18547
         _ExtentY        =   2328
         _Version        =   393216
         AllowUpdate     =   -1  'True
         AllowArrows     =   -1  'True
         BackColor       =   16777215
         HeadLines       =   1
         RowHeight       =   15
         TabAcrossSplits =   -1  'True
         TabAction       =   2
         FormatLocked    =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   6
         BeginProperty Column00 
            DataField       =   "cItemNo"
            Caption         =   "Product ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "cDesc"
            Caption         =   "Description"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "cUnit"
            Caption         =   "Unit"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "nSRPrice"
            Caption         =   "SRP"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column04 
            DataField       =   "nQty"
            Caption         =   "Quantity"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column05 
            DataField       =   "cStatus"
            Caption         =   "Status"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            BeginProperty Column00 
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   1289.764
            EndProperty
            BeginProperty Column01 
               Locked          =   -1  'True
               ColumnWidth     =   2505.26
            EndProperty
            BeginProperty Column02 
               Locked          =   -1  'True
               ColumnWidth     =   569.764
            EndProperty
            BeginProperty Column03 
               Alignment       =   1
               Locked          =   -1  'True
               ColumnWidth     =   1275.024
            EndProperty
            BeginProperty Column04 
               Alignment       =   1
               ColumnWidth     =   1289.764
            EndProperty
            BeginProperty Column05 
            EndProperty
         EndProperty
      End
   End
End
Attribute VB_Name = "frmMFGProductionOrder"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

'Object variables
Private oPrint As New clsPrinting

Private AutoNum As New clsAutoNumber '---Added
Public MenuName As String '---Added

'Recordset variables
Private WithEvents rsHeader As ADODB.Recordset
Attribute rsHeader.VB_VarHelpID = -1
Private rsBM As ADODB.Recordset
Private WithEvents rsFG As ADODB.Recordset
Attribute rsFG.VB_VarHelpID = -1
Private rsSum As ADODB.Recordset

'ADO Connection variables

Private connHeader As ADODB.Connection
Private connBM As ADODB.Connection
Private connFG As ADODB.Connection

Private connSum As ADODB.Connection

'Form mode enumeration
Enum eMFGPOMode
    Normal
    AddNewEdit
    Find
End Enum
Public Mode As eMFGPOMode

Private lSystemGenerated As Boolean
Public strNo As String

'Other declarations
Public dtgName As String
Public sBit As String
Private vBM As Variant 'Recordset bookmark variable

'Security Acess Level variables
Public lACNew As Boolean
Public lACEdit As Boolean
Public lACDelete As Boolean
Public lACPost As Boolean
Public lACCancel As Boolean
Public lACPrint As Boolean

Public lAddDelete As Boolean

Private lSysTransDate As Boolean 'add by denz:2/17/2011 for transdate

Private Sub cboBM_Click()
    rsBM!cStatus = cboBM
End Sub

Private Sub cboBM_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
        rsBM!cStatus = cboBM
        cboBM.Visible = False
        TBNewLine
        dtgBM.SetFocus
    ElseIf KeyCode = vbKeyEscape Then
        cboBM.Visible = False
    End If
End Sub

Private Sub cboBM_LostFocus()
        cboBM.Visible = False
End Sub

Private Sub cboType_Click()
    txtType = Trim(cboType)
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(cboType) = "From SO" Then
        txtRefNo.TabStop = True
        cmdPickSO.TabStop = True
        txtRefNo.Locked = True
        txtRefNo = ""
        cmdPickSO.Enabled = True
    Else
        txtRefNo.TabStop = False
        cmdPickSO.TabStop = False
        txtRefNo.Locked = True
        txtRefNo = ""
        cmdPickSO.Enabled = False
    End If
End Sub

Private Sub cboType_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

Private Sub cmdPickSO_Click()
    
    If Mode <> AddNewEdit Then Exit Sub
    
    If Trim(cboType) = "" Then
        MsgBox "Please select transaction type.", vbInformation, "ComUnion"
        cboType.SetFocus
        Exit Sub
    End If
    
    If Trim(cboType) <> "From SO" Then Exit Sub
    frmARDRList.mDRType = MFGProductionOrder
    frmARDRList.Show vbModal
    If Trim(txtRefNo) <> "" Then SendKeys "{Tab}"

End Sub

Private Sub dtgBM_AfterColUpdate(ByVal ColIndex As Integer)
    
    If Mode <> AddNewEdit Then Exit Sub
    Select Case ColIndex
        Case 0
            If GetValueFrTable("cItemNo", "ITEM", "cItemNo = '" & Trim(dtgBM.Columns(0).Value) & "'") <> "" Then
                GetInitialItemValues rsBM
                dtgBM.Col = 4
                dtgBM.Columns(4).Value = 0
            End If
        Case 4
            GetStatus rsBM!cItemNo
            
        'mon2
        cn.Execute "update PRODUCTION_BM set nQty = '" & dtgBM.Columns(4).Value & "', cStatus = '" & dtgBM.Columns(5).Value & "' WHERE cTranNo = '" & rsHeader!cTranNo & "' AND cCompanyID = '" & COID & "' and cItemNo = '" & rsBM!cItemNo & "' and cItemNoFG = '" & rsFG!cItemNo & "'"
        
    End Select
    
End Sub

Private Sub dtgBM_ButtonClick(ByVal ColIndex As Integer)

    If Mode <> AddNewEdit Then Exit Sub
    Select Case ColIndex
        Case 0
            If Trim(dtgBM.Columns(0).Text) <> "" Then Exit Sub
            If lPickListActive Then Exit Sub
            sFilterString = Trim(dtgBM.Columns(0).Text)
            frmITGPickList.mType = Product
            frmITGPickList.Show vbModal
            rsBM!cItemNo = Trim(frmITGPickList.mCode) & ""
            If (Trim(frmITGPickList.mName) & "") <> "" Then
                GetInitialItemValues rsBM
                dtgBM.Col = 4
                dtgBM.Columns(4).Value = 0
                
                'mon1
                If rsBM.RecordCount = 0 Then Exit Sub
                If rsHeader.State <> adStateOpen Then
                OpenNewConnection connBM
                OpenRecordsetWithCN rsBM, "*", "PRODUCTION_BM", connBM, "WHERE 1 = 0"
                End If
                Set dtgBM.DataSource = rsBM
                rsBM!cItemNoFG = dtgFG.Columns(0).Value
                rsBM!nAddDelete = 1

                connBM.BeginTrans
                rsBM.UpdateBatch adAffectCurrent
                connBM.CommitTrans
                
                
            End If
        Case 5
            Call MoveCombo(cboBM, dtgBM, dtgBM.Columns(5))
            ComboLoadValue cboBM, Trim(dtgBM.Columns(5).Text)
    End Select

End Sub

'Set the datagrid as active control
Private Sub dtgBM_Click()
    If Mode = AddNewEdit Then dtgName = dtgBM.Name
End Sub

Private Sub dtgBM_Error(ByVal DataError As Integer, Response As Integer)
    Response = 0
End Sub

Private Sub dtgBM_GotFocus()
    dtgName = dtgBM.Name
End Sub

Private Sub dtgBM_KeyDown(KeyCode As Integer, Shift As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    If (Shift = vbCtrlMask And KeyCode = 45) Then
        TBNewLine
    ElseIf (Shift = vbCtrlMask And KeyCode = 46) Then
        TBDeleteLine
    ElseIf (Shift = vbCtrlMask And KeyCode = 83) Then
        TBSave
    End If
End Sub

Private Sub dtgBM_KeyPress(KeyAscii As Integer)
    
    If Mode <> AddNewEdit Then Exit Sub
    If rsBM.RecordCount = 0 Then Exit Sub
    
    If KeyAscii = 39 Then KeyAscii = 0 'Apostrophe {'}
    
    If KeyAscii = 13 Then
        Select Case dtgBM.Col
            Case 0
                If GetValueFrTable("cItemNo", "ITEM", "cItemNo = '" & Trim(dtgBM.Columns(0).Value) & "'") = "" Then
                    dtgBM_ButtonClick (0) 'use button click
                End If
            Case 5
                If cboBM.Visible = False Then
                    dtgBM_ButtonClick (5)
                    If Trim(dtgBM.Columns(5).Text) <> "" Then cboBM = Trim(dtgBM.Columns(5).Text)
                Else
                    TBNewLine
                    dtgBM.LeftCol = 0
                End If
            Case Else
                SendKeys "{Tab}"
        End Select
    Else
        KeyAscii = Asc(UCase(Chr(KeyAscii))) 'All Upper Case String
    End If

End Sub

'Right click menu popup
Private Sub dtgBM_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Mode <> AddNewEdit Then Exit Sub
    If Button = 2 Then
        dtgName = dtgBM.Name
        PopupMenu ITGLedgerMain.mnuDetail
    End If
End Sub

Private Sub dtgFG_AfterColUpdate(ByVal ColIndex As Integer)
    
    If Mode <> AddNewEdit Then Exit Sub
       Select Case ColIndex
        Case 0
            If GetValueFrTable("cItemNo", "ITEM", "cItemNo = '" & Trim(dtgFG.Columns(0).Value) & "'") <> "" Then
                GetInitialItemValues rsFG
                dtgFG.Col = 4
                dtgFG.Columns(4).Value = 0
            End If
        Case 4
            GetBillOfMaterials Trim(rsFG!cItemNo), rsFG
    End Select
    
End Sub

Private Sub dtgFG_ButtonClick(ByVal ColIndex As Integer)

    If Mode <> AddNewEdit Then Exit Sub
    If cboType.Text = "From SO" Then Exit Sub
    Select Case ColIndex
        Case 0
            If lPickListActive Then Exit Sub
            sFilterString = Trim(dtgFG.Columns(0).Text)
            frmITGPickList.mType = Product
            frmITGPickList.Show vbModal
            rsFG!cItemNo = Trim(frmITGPickList.mCode) & ""
            If (Trim(frmITGPickList.mName) & "") <> "" Then
                GetInitialItemValues rsFG
                dtgFG.Col = 4
                dtgFG.Columns(4).Value = 0
            End If
    End Select

End Sub

'Set the datagrid as active control
Private Sub dtgFG_Click()
    If Mode = AddNewEdit Then dtgName = dtgFG.Name
End Sub

Private Sub dtgFG_Error(ByVal DataError As Integer, Response As Integer)
    Response = 0
End Sub

Private Sub dtgFG_GotFocus()
    dtgName = dtgFG.Name
End Sub

Private Sub dtgFG_KeyDown(KeyCode As Integer, Shift As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    If (Shift = vbCtrlMask And KeyCode = 45) Then
        TBNewLine
    ElseIf (Shift = vbCtrlMask And KeyCode = 46) Then
        TBDeleteLine
    ElseIf (Shift = vbCtrlMask And KeyCode = 83) Then
        TBSave
    End If
End Sub

Private Sub dtgFG_KeyPress(KeyAscii As Integer)
    
    If Mode <> AddNewEdit Then Exit Sub
    If rsFG.RecordCount = 0 Then Exit Sub
    
    If KeyAscii = 39 Then KeyAscii = 0 'Apostrophe {'}
    
    If KeyAscii = 13 Then
        Select Case dtgFG.Col
            Case 0
                If GetValueFrTable("cItemNo", "ITEM", "cItemNo = '" & Trim(dtgFG.Columns(0).Value) & "'") = "" Then
                    dtgFG_ButtonClick (0) 'use button click
                End If
            Case 4
                TBNewLine
                dtgFG.LeftCol = 0
            Case Else
                SendKeys "{Tab}"
        End Select
    Else
        KeyAscii = Asc(UCase(Chr(KeyAscii))) 'All Upper Case String
    End If

End Sub

'Right click menu popup
Private Sub dtgFG_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If cboType.Text <> "For stock" Then Exit Sub
    If Mode <> AddNewEdit Then Exit Sub
    If Button = 2 Then
        dtgName = dtgFG.Name
        PopupMenu ITGLedgerMain.mnuDetail
    End If
End Sub

Private Sub dtgList_HeadClick(ByVal ColIndex As Integer)
    SortGrid dtgList, ColIndex, rsHeader
End Sub

Private Sub dtgSum_AfterColUpdate(ByVal ColIndex As Integer)
    If Mode <> AddNewEdit Then Exit Sub
       Select Case ColIndex
        Case 0
            If GetValueFrTable("cItemNo", "ITEM", "cItemNo = '" & Trim(dtgSum.Columns(0).Value) & "'") <> "" Then
                rsSum!cDesc = Trim(GetValueFrTable("cDesc", "ITEM", "cItemNo = '" & Trim(rsSum!cItemNo) & "'")) & ""
            End If
    
    End Select
End Sub

Private Sub dtgSum_ButtonClick(ByVal ColIndex As Integer)
    
    If Mode <> AddNewEdit Then Exit Sub
    If cboType.Text = "From SO" Then Exit Sub
    Select Case ColIndex
        Case 0
            If lPickListActive Then Exit Sub
            sFilterString = Trim(dtgSum.Columns(0).Text)
            frmITGPickList.mType = Product
            frmITGPickList.POLabor = "labor"
            frmITGPickList.Show vbModal
            frmITGPickList.POLabor = ""
            rsSum!cItemNo = Trim(frmITGPickList.mCode) & ""
            If (Trim(frmITGPickList.mName) & "") <> "" Then
                rsSum!cDesc = Trim(GetValueFrTable("cDesc", "ITEM", "cItemNo = '" & Trim(rsSum!cItemNo) & "'")) & ""

                'mon1s
                If rsSum.RecordCount = 0 Then Exit Sub
                If rsHeader.State <> adStateOpen Then
                OpenNewConnection connSum
                OpenRecordsetWithCN rsSum, "*", "PRODUCTION_S", connSum, "WHERE 1 = 0"
                End If
                Set dtgSum.DataSource = rsSum
                rsSum!cItemNoFG = dtgFG.Columns(0).Value
                rsSum!nAddDelete = 1

                connSum.BeginTrans
                rsSum.UpdateBatch adAffectCurrent
                connSum.CommitTrans

            End If
    End Select

End Sub

Private Sub dtgSum_Click()
If Mode = AddNewEdit Then dtgName = dtgSum.Name
End Sub

Private Sub dtgSum_Error(ByVal DataError As Integer, Response As Integer)
Response = 0
End Sub

Private Sub dtgSum_GotFocus()
    dtgName = dtgFG.Name
End Sub

Private Sub dtgSum_KeyPress(KeyAscii As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    If rsSum.RecordCount = 0 Then Exit Sub
    
    If KeyAscii = 39 Then KeyAscii = 0 'Apostrophe {'}
    
    If KeyAscii = 13 Then
        Select Case dtgSum.Col
            Case 0
                If GetValueFrTable("cItemNo", "ITEM", "cItemNo = '" & Trim(dtgSum.Columns(0).Value) & "'") = "" Then
                    dtgSum_ButtonClick (0) 'use button click
                End If
            Case 3
                TBNewLine
                dtgSum.LeftCol = 0
            Case Else
                SendKeys "{Tab}"
        End Select
    Else
        KeyAscii = Asc(UCase(Chr(KeyAscii))) 'All Upper Case String
    End If
End Sub

Private Sub dtgSum_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Mode <> AddNewEdit Then Exit Sub
    If cboType.Text = "From SO" Then Exit Sub
    If Button = 2 Then
        dtgName = dtgSum.Name
        PopupMenu ITGLedgerMain.mnuDetail
    End If
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Dim iKey As Integer
    iKey = ToolbarIndex(KeyCode, Shift)
    If iKey <> 0 Then
        If ITGLedgerMain.tbrMain.Buttons(iKey).Enabled = True Then
            ToolbarFunction iKey
        End If
    End If
End Sub

'Set Your Object
Private Sub Form_Load()
    Set FrmName = Me
    FormSetup
    
    AcessBit Me, GetValueFrTable("AccessLevel", "SEC_ACCESSLEVEL", "RoleID = '" & SecUserRole & "' AND [Module] = 'MI08'")
    
    Set rsHeader = New ADODB.Recordset
    Set rsSum = New ADODB.Recordset
    Set rsBM = New ADODB.Recordset
    Set rsFG = New ADODB.Recordset
    
    
    

    FormLocking True
    FormSearch True
    SearchObj True
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
    BitVisible ITGLedgerMain.tbrMain, True, True
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = True

    Mode = Find
    txtTranNo.Locked = False
    
End Sub

'Activate your Toolbar Mode
Private Sub Form_Activate()
    TBBitReload
End Sub

'Release your Object
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
    If Mode = AddNewEdit Then
        MsgBox "Unable to close. You are in Add/New/Edit mode." & vbCr & _
            " Must Save or Undo", vbCritical, Me.Caption
        Cancel = True
        Exit Sub
    End If
    
    CloseMenuTab ITGLedgerMain
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , , , , , , , True
    BitVisible ITGLedgerMain.tbrMain
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = False

    
    
    
    
    Set oPrint = Nothing
    Set rsHeader = Nothing
    Set rsSum = Nothing
    Set rsBM = Nothing
    Set rsFG = Nothing
    Set connHeader = Nothing
    Set connSum = Nothing
    Set connBM = Nothing
    Set connFG = Nothing
    
    Set frmMFGProductionOrder = Nothing

    lCloseWindow = True
    
'    'oForm(Me.Tag).Mode = 1
'    'oForm(Me.Tag).Tag = Me.Tag
End Sub

'Add new record to the recordset
Public Sub TBNew()

    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
    txtTranNo.BackColor = &HE0FFFF
    Mode = AddNewEdit
    
    lAddDelete = True

    If rsHeader.State <> adStateOpen Then
        OpenNewConnection connHeader
        OpenNewConnection connSum
        OpenNewConnection connBM
        OpenNewConnection connFG
        OpenRecordsetWithCN rsSum, "*", "PRODUCTION_S", connSum, "WHERE 1 = 0"
        OpenRecordsetWithCN rsBM, "*", "PRODUCTION_BM", connBM, "WHERE 1 = 0"
        OpenRecordsetWithCN rsFG, "*", "PRODUCTION_FG", connFG, "WHERE 1 = 0"
        OpenRecordsetWithCN rsHeader, "*", "PRODUCTION", connHeader, "WHERE 1 = 0"
        SetDataSource
        SetDataField
    Else
        vBM = rsHeader.Bookmark
    End If

    rsHeader.AddNew
    rsHeader!cCompanyID = COID
    rsHeader!dDate = Date
    
    Set FrmName = Me
    FormLocking False
    ClrRequired &HC0&
    SSTab1.ActiveTab = 0
    rsHeader!cType = "For stock"
    txtTranNo.SetFocus

'    'System generated number
'    lSystemGenerated = GetValueFrTable("lBit", "SYSTEM_OPTION", "cCode = 'AUTO_NUMBER_PRDO' ")
'    If lSystemGenerated Then rsHeader!cTranNo = GetAutoCtrlNo(rsHeader, "AUTO_NUMBER_PRDO", "PRODUCTION", "cTranNo")
    
    MenuName = "AUTO_NUMBER_PO"
    lSystemGenerated = GetValueFrTable("lAutoNo", "system_autonumber", "cCode = '" & MenuName & "'")
    If lSystemGenerated Then rsHeader!cTranNo = AutoNum.Generate_CtrlNo2(MenuName, Format(Now, "mm/dd/yyyy"))
    
    lSysTransDate = GetValueFrTable("lTransDate", "system_autonumber", "cCode = '" & MenuName & "' ") 'add by denz:2/17/2011
    If lSysTransDate Then
        dtbDate.Enabled = True
    Else: dtbDate.Enabled = False
    End If
    
    strNo = rsHeader!cTranNo
    
    lAddDelete = False
    
End Sub

'Undo all changes to the recordset
Public Sub TBUndoAll()
On Error GoTo ErrorHandler

    lAddDelete = True
    
    Mode = Normal
    
    If rsHeader.Status = adRecNew Then TBUndoCurrent
    
    rsHeader.CancelBatch adAffectAll
    rsBM.CancelBatch adAffectAll
    rsFG.CancelBatch adAffectAll
    
    'mon1
    cn.Execute "DELETE PRODUCTION_BM WHERE cTranNo = '" & txtTranNo.Text & "' AND cCompanyID = '" & COID & "' and nAddDelete = '1'"
    cn.Execute "update PRODUCTION_BM set nAddDelete = '0' WHERE cTranNo = '" & txtTranNo.Text & "' AND cCompanyID = '" & COID & "' and nAddDelete = '2'"
        
    
    'mon1s
    cn.Execute "DELETE PRODUCTION_S WHERE cTranNo = '" & txtTranNo.Text & "' AND cCompanyID = '" & COID & "' and nAddDelete = '1'"
    cn.Execute "update PRODUCTION_S set nAddDelete = '0' WHERE cTranNo = '" & txtTranNo.Text & "' AND cCompanyID = '" & COID & "' and nAddDelete = '2'"
    
    UnbindControls
    
    If rsHeader.RecordCount <> 0 Then rsHeader.Bookmark = vBM
    
    Set FrmName = Me
    FormLocking True
    
    If rsHeader.RecordCount <> 0 Then
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , lACCancel, , , True, True, lACPrint, True
    Else
        RSZero
        Mode = Find
    End If

    sbRS.Panels(2) = ""
    
    SetDataSource
    SetDataField

    lAddDelete = False
    
ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217842 Then 'Operation was cancelled. (Error returned by ITGDateBox)
        TBUndoAll
    End If

End Sub

'Undo changes on the current record
Public Sub TBUndoCurrent()
On Error GoTo ErrorHandler


   'mon1
    cn.Execute "DELETE PRODUCTION_BM WHERE cTranNo = '" & txtTranNo.Text & "' AND cCompanyID = '" & COID & "' and nAddDelete = '1'"
    cn.Execute "update PRODUCTION_BM set nAddDelete = '0' WHERE cTranNo = '" & txtTranNo.Text & "' AND cCompanyID = '" & COID & "' and nAddDelete = '2'"
        
    
    'mon1s
    cn.Execute "DELETE PRODUCTION_S WHERE cTranNo = '" & txtTranNo.Text & "' AND cCompanyID = '" & COID & "' and nAddDelete = '1'"
    cn.Execute "update PRODUCTION_S set nAddDelete = '0' WHERE cTranNo = '" & txtTranNo.Text & "' AND cCompanyID = '" & COID & "' and nAddDelete = '2'"
    
    
    GetChild
    If rsHeader.Status = adRecNew Then
        rsBM.CancelBatch adAffectAll
        rsFG.CancelBatch adAffectAll
        rsHeader.CancelUpdate
    Else
        rsHeader.CancelBatch adAffectCurrent
        rsBM.CancelBatch adAffectAll
        rsFG.CancelBatch adAffectAll
    End If
   
       
    If rsHeader.RecordCount = 0 Then RSZero
    
ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217842 Then 'Operation was cancelled. (Error returned by ITGDateBox)
        TBUndoCurrent
        
        Else
        Resume Next
        
    End If

End Sub

'Save all changes
Public Sub TBSave()
Dim OKUpdate As Boolean
On Error GoTo ErrHandler

    lAddDelete = True
    
    'Audit Trail
    lBoolean = False
    If rsHeader.Status = adRecNew Then lBoolean = True
    
    If Not MandatoryOK Then Exit Sub
    
    'System generated number
    If rsHeader.Status = adRecNew Then
    
    
        If lSystemGenerated Then
            'If ChkCtrlNo(rsHeader, "AUTO_NUMBER_PRDO", "PRODUCTION", "cTranNo", rsHeader!cTranNo) <> rsHeader!cTranNo Then
            If AutoNum.Check_CtrlNo2(rsHeader, "Production", "cTranNo", rsHeader!cTranNo, MenuName, rsHeader!dDate) <> rsHeader!cTranNo Then

                GetChild
                
                rsHeader!cTranNo = strNo
                
                If rsBM.RecordCount <> 0 Then rsBM.MoveFirst
                Do Until rsBM.EOF
                    rsBM!cTranNo = strNo
                    rsBM.MoveNext
                Loop

                If rsFG.RecordCount <> 0 Then rsFG.MoveFirst
                Do Until rsFG.EOF
                    rsFG!cTranNo = strNo
                    rsFG.MoveNext
                Loop
                
                GetChild
            End If
        End If
    End If
    
    OKUpdate = False
    cn.BeginTrans
    connHeader.BeginTrans
    'connBM.BeginTrans
    connFG.BeginTrans
    
    rsHeader.UpdateBatch adAffectAll
    'rsBM.UpdateBatch adAffectAll
    rsFG.UpdateBatch adAffectAll
    
    cn.CommitTrans
    connHeader.CommitTrans
    'connBM.CommitTrans
    connFG.CommitTrans
    
    'mon1
    cn.Execute "DELETE PRODUCTION_BM WHERE cTranNo = '" & rsHeader!cTranNo & "' AND cCompanyID = '" & COID & "' and nAddDelete = '2'"
    cn.Execute "update PRODUCTION_BM set nAddDelete = '0' WHERE cTranNo = '" & rsHeader!cTranNo & "' AND cCompanyID = '" & COID & "' and nAddDelete = '1'"
    
    
    'mon1s
    cn.Execute "DELETE PRODUCTION_S WHERE cTranNo = '" & rsHeader!cTranNo & "' AND cCompanyID = '" & COID & "' and nAddDelete = '2'"
    cn.Execute "update PRODUCTION_S set nAddDelete = '0' WHERE cTranNo = '" & rsHeader!cTranNo & "' AND cCompanyID = '" & COID & "' and nAddDelete = '1'"
    
    Call autoDR
    Call autoWRR
    
    lAddDelete = False
    
    OKUpdate = True
    
    
    Set FrmName = Me
    FormLocking True
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , lACCancel, , , True, True, lACPrint, True
    Mode = Normal
    
    'Audit trail
    UpdateLogFile "Production Order", Trim(txtTranNo), IIf(lBoolean, "Inserted", "Updated")

    'update system generated number
'    If lBoolean Then
'        If lSystemGenerated And strNo = rsHeader!cTranNo Then UpdateControlNo strNo, rsHeader!cTranNo, "AUTO_NUMBER_PRDO"
'    End If
    
    If lBoolean Then
        If lSystemGenerated And strNo = rsHeader!cTranNo Then
            UpdateControlNo strNo, rsHeader!cTranNo, "AUTO_NUMBER_PO"
            AutoNum.Update_CtrlNo2 strNo, MenuName, Format(Now, "mm/dd/yyyy")
        End If
    End If

    MsgBox "Record/s successfully saved.", vbInformation, "ComUnion"
    sbRS.Panels(2) = ""
        
ErrHandler:
    cboBM.Visible = False
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217864 Then
        OKUpdate = True
        cn.RollbackTrans
        connHeader.RollbackTrans
        connBM.RollbackTrans
        connFG.RollbackTrans
        MsgBox "Record cannot be updated. Some values may have been changed by other user/s since last read." & vbCr & _
                "Records will be automatically refreshed. All changes made to the record will be gone upon refresh.", vbInformation, "ComUnion"
        vBookMark = rsHeader.Bookmark
        UnbindControls
        rsHeader.Requery
        rsBM.Requery
        rsFG.Requery
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , lACCancel, , , True, True, lACPrint, True
        Mode = Normal
        If rsHeader.RecordCount <> 0 Then
            Set FrmName = Me
            FormLocking True
            SetDataField
            SetDataSource
            rsHeader.Bookmark = vBookMark
        Else
            RSZero
        End If
    End If
    If Not OKUpdate Then
        MsgBox "Transaction update failed.", vbInformation, "ComUnion"
        cn.RollbackTrans
        connHeader.RollbackTrans
        connBM.RollbackTrans
        connFG.RollbackTrans
        ErrorLog err.Number, err.Description, Me.Name 'Error log
    End If
    
End Sub

'Sets the form & recorset to add/edit mode
Public Sub TBEdit()
    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled. Edit is not allowed.", vbExclamation, "ComUnion"
        Exit Sub
    End If
    If Not AllowEdit Then Exit Sub
    Mode = AddNewEdit
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
    Set FrmName = Me
    FormLocking False
    ClrRequired &HC0&
    txtRefNo.Locked = True
    cmdPickSO.Enabled = False
    txtTranNo.Locked = True
    SSTab1.ActiveTab = 0
    dtbDate.SetFocus
    vBM = rsHeader.Bookmark
    
    MenuName = "AUTO_NUMBER_PO"
    lSysTransDate = GetValueFrTable("lTransDate", "system_autonumber", "cCode = '" & MenuName & "' ") 'add by denz:2/17/2011
    If lSysTransDate Then
        dtbDate.Enabled = True
    Else: dtbDate.Enabled = False
    End If
End Sub

'Delete record
Public Sub TBDelete()
On Error GoTo ErrorHandler

    sID = Trim(txtTranNo)
    
    If rsHeader.RecordCount = 0 Then Exit Sub

    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled. Deletion is not allowed.", vbExclamation, "ComUnion"
        Exit Sub
    End If
    
    If MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, "ComUnion") = vbNo Then Exit Sub
    
    If Not AllowDelete("delete") Then Exit Sub
    
    GetChild
    If rsBM.RecordCount <> 0 Then
        rsBM.MoveFirst
        Do Until rsBM.RecordCount = 0
            rsBM.Delete adAffectCurrent
            If rsBM.RecordCount <> 0 Then rsBM.MoveFirst
        Loop
    End If
    If rsFG.RecordCount <> 0 Then
        rsFG.MoveFirst
        Do Until rsFG.RecordCount = 0
            rsFG.Delete adAffectCurrent
            If rsFG.RecordCount <> 0 Then rsFG.MoveFirst
        Loop
    End If
    
    
    
    'Audit trail
    UpdateLogFile "Production Order", Trim(txtTranNo), "Deleted"

    rsHeader.Delete adAffectCurrent
    
    rsBM.UpdateBatch adAffectAll
    rsFG.UpdateBatch adAffectAll
    rsHeader.UpdateBatch adAffectAll
    
    cn.Execute "DELETE PRODUCTION_BM WHERE cTranNo = '" & sID & "' AND cCompanyID = '" & COID & "'"
    
    
    TBPrevRec

    Mode = Normal

    If rsHeader.RecordCount = 0 Then
        RSZero
    End If

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217864 Then
        cn.Execute "DELETE PRODUCTION_BM WHERE cTranNo = '" & sID & "' AND cCompanyID = '" & COID & "'"
        cn.Execute "DELETE PRODUCTION_FG WHERE cTranNo = '" & sID & "' AND cCompanyID = '" & COID & "'"
        cn.Execute "DELETE PRODUCTION WHERE cTranNo = '" & sID & "' AND cCompanyID = '" & COID & "'"
        Resume Next
    End If

End Sub

'Search using the frmITGSearch
Public Sub TBFind()
    Mode = Normal
    txtTranNo.Locked = True
    frmITGSearch.Show 'vbModal
End Sub

'Search using the recordset primary key
Public Sub TBFindPrimary()
Dim sTemp As String
If Mode = Find Then
    FormWaitShow App.Path & "\Transmit.avi", "Loading data . . ."
            
    OpenNewConnection connHeader
    OpenNewConnection connSum
    OpenNewConnection connBM
    OpenNewConnection connFG
    
    Set rsHeader = Nothing
    Set rsSum = Nothing
    Set rsBM = Nothing
    Set rsFG = Nothing
    Set rsHeader = New ADODB.Recordset
    Set rsSum = New ADODB.Recordset
    Set rsBM = New ADODB.Recordset
    Set rsFG = New ADODB.Recordset

    sTemp = Trim$(GetSearchString)
    If sTemp = "ERROR" Then
        MsgBox "Only Allows A - Z, 0 - 9, '.', ',' and %(wildcard)", vbExclamation, ""
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
        txtTranNo.Locked = False
        txtTranNo.SetFocus
        Exit Sub
    End If
             
    OpenRecordsetWithCN rsHeader, "*", "PRODUCTION", connHeader, IIf(sTemp = "", "", " WHERE " & sTemp)
    OpenRecordsetWithCN rsBM, "*", "PRODUCTION_BM", connBM
    OpenRecordsetWithCN rsFG, "*", "PRODUCTION_FG", connFG

    OpenRecordsetWithCN rsSum, "*", "PRODUCTION_S", connSum, IIf(sTemp = "", "", " WHERE cTranNo IN (SELECT cTranNo FROM PRODUCTION WHERE " & sTemp & ")")
    OpenRecordsetWithCN rsBM, "*", "PRODUCTION_BM", connBM, IIf(sTemp = "", "", " WHERE cTranNo IN (SELECT cTranNo FROM PRODUCTION WHERE " & sTemp & ")")
    OpenRecordsetWithCN rsFG, "*", "PRODUCTION_FG", connFG, IIf(sTemp = "", "", " WHERE cTranNo IN (SELECT cTranNo FROM PRODUCTION WHERE " & sTemp & ")")
     
    Set FrmName = Me
    FormLocking True

    If rsHeader.RecordCount = 0 Then
        FormWaitHide
        MsgBox "No matching record/s found.", vbInformation, "ComUnion Search"
        RSZero
        FormSearch True
        SearchObj True
        Mode = Find
        Exit Sub
    End If
    SetDataSource
    SetDataField
    txtTranNo.BackColor = &HE0FFFF
    Mode = Normal
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , lACCancel, , , True, True, lACPrint, True

    FormWaitHide
Else
    RSZero
    FormSearch True
    SearchObj True
    Mode = Find
    

End If

End Sub

'Reload menu buttons (do not delete this sub)
Public Sub TBBitReload()
    BitVisible ITGLedgerMain.tbrMain, True, True
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = True
    BitReload ITGLedgerMain, Me, ITGLedgerMain.tbrMain, sBit
    Set FrmName = Me
    dtgName = dtgFG.Name
End Sub

'Close active window
Public Sub TBCloseWindow()
    Unload Me
End Sub

'Move first
Public Sub TBFirstRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveFirst rsHeader
    

End Sub

'Move previuos
Public Sub TBPrevRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MovePrevious rsHeader
    

End Sub

'Move next
Public Sub TBNextRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveNext rsHeader
    

End Sub

'Move last
Public Sub TBLastRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveLast rsHeader
    

End Sub

'Add new line to the detail recordset
Public Sub TBNewLine()
    
    If rsHeader!cTranNo = "" Then Exit Sub
    
    If dtgName = "dtgBM" Then
    'mon1
        If rsFG.RecordCount = 0 Then Exit Sub
        OpenNewConnection connBM
        Set rsBM = Nothing
        Set rsBM = New ADODB.Recordset
        OpenRecordsetWithCN rsBM, "*", "PRODUCTION_BM", connBM, "WHERE cTranNo = '" & Trim(rsHeader!cTranNo) & "' and cItemNoFG = '" & rsFG!cItemNo & "' and nAddDelete <> '2'"
        Set dtgBM.DataSource = rsBM
        
        rsBM.AddNew
        rsBM!cCompanyID = COID
        rsBM!cTranNo = Trim(rsHeader!cTranNo)
        dtgBM.Col = 0
        dtgBM.Columns(0).Value = ""
        If rsBM.RecordCount <> 0 Then rsBM.MoveLast
        dtgBM.SetFocus
    ElseIf dtgName = "dtgFG" Then
        If cboType.Text <> "For stock" Then Exit Sub
        rsFG.AddNew
        rsFG!cCompanyID = COID
        rsFG!cTranNo = Trim(rsHeader!cTranNo)
        dtgFG.Col = 0
        dtgFG.Columns(0).Value = ""
        GetChild
        If rsFG.RecordCount <> 0 Then rsFG.MoveLast
        dtgFG.SetFocus
        
'    ElseIf dtgName = "dtgSum" Then
'
'    'mon1s
'        If rsFG.RecordCount = 0 Then Exit Sub
'        OpenNewConnection connSum
'        Set rsSum = Nothing
'        Set rsSum = New ADODB.Recordset
'        OpenRecordsetWithCN rsSum, "*", "PRODUCTION_S", connSum, "WHERE cTranNo = '" & Trim(rsHeader!cTranNo) & "' and cItemNoFG = '" & rsFG!cItemNo & "' and nAddDelete <> '2'"
'        Set dtgSum.DataSource = rsSum
'
'        rsSum.AddNew
'        rsSum!cCompanyID = COID
'        rsSum!cTranNo = Trim(rsHeader!cTranNo)
'        dtgSum.Col = 0
'        dtgSum.Columns(0).Value = ""
'        If rsSum.RecordCount <> 0 Then rsSum.MoveLast
'        dtgSum.SetFocus
        
    End If
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True

End Sub

'Delete line in the detail recordset
Public Sub TBDeleteLine()
On Error GoTo ErrorHandler

    If dtgName = dtgBM.Name Then
        If rsBM.RecordCount = 0 Then Exit Sub
    'mon1
        rsBM!nAddDelete = 2
        connBM.BeginTrans
        rsBM.UpdateBatch adAffectCurrent
        connBM.CommitTrans

        vBookMark = dtgBM.Bookmark
        'GetChild
        dtgBM.Bookmark = vBookMark
        rsBM.Delete adAffectCurrent
        cn.Execute "DELETE PRODUCTION_BM WHERE cTranNo = '" & rsHeader!cTranNo & "' AND cCompanyID = '" & COID & "' and cItemNoFG = '" & rsFG!cItemNo & "' and nAddDelete = '1'"
            
    ElseIf dtgName = dtgFG.Name Then
        If cboType.Text <> "For stock" Then Exit Sub
        If rsFG.RecordCount = 0 Then Exit Sub
        vBookMark = dtgFG.Bookmark
        GetChild
        dtgFG.Bookmark = vBookMark
        rsFG.Delete adAffectCurrent
        
        GetChild
        
    ElseIf dtgName = dtgSum.Name Then
    'mon1s
        rsSum!nAddDelete = 2
        connSum.BeginTrans
        rsSum.UpdateBatch adAffectCurrent
        connSum.CommitTrans

        vBookMark = dtgSum.Bookmark
        'GetChild
        dtgSum.Bookmark = vBookMark
        rsSum.Delete adAffectCurrent
        cn.Execute "DELETE PRODUCTION_S WHERE cTranNo = '" & rsHeader!cTranNo & "' AND cCompanyID = '" & COID & "' and cItemNoFG = '" & rsFG!cItemNo & "' and nAddDelete = '1'"
        
    End If
    'GetChild

    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Undo All
Public Sub TBUndoLineAll()
On Error GoTo ErrorHandler

    MsgBox "Unavailable on " & Me.Name

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Undo current line
Public Sub TBUndoLineCurrent()
    MsgBox "Unavailable on " & Me.Name
End Sub

'Post current record
Public Sub TBPostRecord()
    MsgBox "Unavailable on " & Me.Name
End Sub

'Cancel current record
Public Sub TBCancelRecord()
On Error GoTo ErrorHandler
    
    If rsHeader.RecordCount = 0 Then Exit Sub

    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled.", vbExclamation, "ComUnion"
        Exit Sub
    End If
    
    If MsgBox("Are you sure you want to cancel this record?", vbQuestion + vbYesNo, "ComUnion") = vbNo Then Exit Sub

    If Not AllowDelete("cancel") Then Exit Sub
    
    'Audit trail
    UpdateLogFile "Production Order", Trim(txtTranNo), "Cancelled"

    cn.Execute ("UPDATE PRODUCTION SET lCancelled = 1 WHERE cTranNo = '" & Trim(txtTranNo) & "' AND cCompanyID = '" & COID & "'")
    
    sbRS.Panels(5) = "CANCELLED"
    Mode = Normal
    
    rsHeader!lCancelled = True
    rsHeader.UpdateBatch adAffectAll

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Print
Public Sub TBPrintRecord()
    cModule = "Production_Order"
    oPrint.PrintReceipt Trim(txtTranNo)
End Sub

'Sets the data source of the controls
Sub SetDataSource()
    Set FrmName = Me
    BindControls rsHeader
    Set dtgList.DataSource = rsHeader
    Set dtgSum.DataSource = rsSum
    Set dtgBM.DataSource = rsBM
    Set dtgFG.DataSource = rsFG
    
    
End Sub

'Sets the data field for every bounded controls
Sub SetDataField()
    With rsHeader
        txtTranNo.DataField = !cTranNo
        dtbDate.DataField = !dDate
        txtType.DataField = !cType
        txtRefNo.DataField = !cRefNo
        dtbNeeded.DataField = !dNeeded
        txtRemarks.DataField = !cRemarks
    End With
End Sub

'mon1
'Private Sub rsFG_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
'' rsBM.Filter = "cTranNo = '" & Trim(rsHeader!cTranNo) & "' and cItemNoFG = '" & rsFG!cItemNo & "'"
'        If rsFG.RecordCount = 0 Then Exit Sub
'        If lAddDelete = True Then Exit Sub
'        OpenNewConnection connBM
'        Set rsBM = Nothing
'        Set rsBM = New ADODB.Recordset
'        OpenRecordsetWithCN rsBM, "*", "PRODUCTION_BM", connBM, "WHERE cTranNo = '" & Trim(rsHeader!cTranNo) & "' and cItemNoFG = '" & rsFG!cItemNo & "'"
'        Set dtgFG.DataSource = rsBM
'
''mon1s
'        OpenNewConnection connSum
'        Set rsSum = Nothing
'        Set rsSum = New ADODB.Recordset
'        OpenRecordsetWithCN rsSum, "*", "PRODUCTION_S", connSum, "WHERE cTranNo = '" & Trim(rsHeader!cTranNo) & "' and cItemNoFG = '" & rsFG!cItemNo & "'"
'        Set dtgSum.DataSource = rsSum
'
'End Sub

Private Sub rsHeader_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
On Error GoTo ErrorHandler

    If Not (rsHeader.EOF) Or Not (rsHeader.BOF) Then
        'Status bar setup
        sbRS.Panels(1) = "Record: " & IIf((rsHeader.AbsolutePosition = -2), "0", rsHeader.AbsolutePosition) & "/" & rsHeader.RecordCount

        If rsHeader.Status <> adRecNew Then
            txtTranNo.Locked = True
        Else
            txtTranNo.Locked = False
        End If

        If Mode = AddNewEdit Then
            Select Case rsHeader.Status
                Case adRecNew
                    sbRS.Panels(2) = "New"
                Case adRecModified
                    sbRS.Panels(2) = "Modified"
                Case Else
                    sbRS.Panels(2) = ""
            End Select
        Else
            sbRS.Panels(2) = ""
        End If
        
        GetChild
    
        If rsHeader!lCancelled = True Then
            sbRS.Panels(5) = "CANCELLED"
        Else
            sbRS.Panels(5) = ""
        End If
    Else
        sbRS.Panels(1) = "Record: 0/0"
        sbRS.Panels(2) = ""
        txtTranNo.Locked = False
    End If

    If Mode = AddNewEdit Then
        dtgBM.Refresh
        dtgFG.Refresh
    End If

ErrorHandler:
    'Err.Number -2147217885
    'Description - Row handle referred to a deleted row or a row marked for deletion.
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

Private Sub Timer1_Timer()
    If Mode = AddNewEdit Then
        SSTab1.TabEnabled(1) = False
    Else
        SSTab1.TabEnabled(1) = True
    End If
End Sub

Private Sub txtRemarks_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If rsFG.RecordCount = 0 Then TBNewLine
End Sub

Private Sub txtTranNo_LostFocus()
    'Does Code Already Exist
    If Mode = AddNewEdit Then
        If Trim(txtTranNo) = "" Then
            MsgBox "Empty primary input.", vbInformation, "ComUnion"
            If FrmName.Name <> Me.Name Then PreviousTab frmComUnionMenuTab
            txtTranNo.SetFocus
        Else
            If rsHeader.Status <> adRecNew Then Exit Sub
            txtTranNo = Trim(txtTranNo)
            If IDExisting(rsHeader, "cTranNo", "PRODUCTION", Trim(rsHeader!cTranNo)) Then
                MsgBox "Trancsaction No. already exist.", vbInformation, "ComUnion"
                If FrmName.Name <> Me.Name Then PreviousTab frmComUnionMenuTab
                txtTranNo.SetFocus
            End If
        End If
    End If
End Sub

'Check if all mandatory fields are complete
Function MandatoryOK() As Boolean

    MandatoryOK = True

    If Trim(txtTranNo) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Transaction Number' is mandatory. Null value is not allowed.", vbInformation, "ComUnion"
        txtTranNo.SetFocus
        Exit Function
    End If
    
    If rsHeader.Status = adRecNew And lSystemGenerated = False Then
        If IDExisting(rsHeader, "cTranNo", "PRODUCTION", Trim(rsHeader!cTranNo)) Then
            MandatoryOK = False
            MsgBox "Transaction No. already exist.", vbInformation, "ComUnion"
            txtTranNo.SetFocus
            Exit Function
        End If
    End If

    'Required fields
    If Trim(dtbDate.Text) = "__/__/____" Then
        MandatoryOK = False
        MsgBox "Field 'Transaction Date' is mandatory. Null value is not allowed.", vbInformation, "ComUnion"
        dtbDate.SetFocus
        Exit Function
    ElseIf Trim(txtType) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Type' is mandatory. Null value is not allowed.", vbInformation, "ComUnion"
        cboType.SetFocus
        Exit Function
    ElseIf Trim(cboType) = "From SO" Then
        If Trim(txtRefNo) = "" Then
            MandatoryOK = False
            MsgBox "Field 'Reference No.' is mandatory. Null value is not allowed.", vbInformation, "ComUnion"
            txtRefNo.SetFocus
            Exit Function
        End If
    End If
    
    GetChild
    
    'Transaction without details
    If rsFG.RecordCount = 0 Then
        MandatoryOK = False
        MsgBox "Cannot save transaction without details.", vbInformation, "ComUnion"
        dtgFG.SetFocus
        Exit Function
    End If
    
    If rsBM.RecordCount <> 0 Then rsBM.MoveFirst
    Do Until rsBM.EOF
        If Trim(rsBM!cStatus) = "Available" Then rsBM!lDRReady = True
        If rsBM.Status = (adRecNew) Or rsBM.Status = (adRecModified) Then
            If IsNull(rsBM!cItemNo) Then
                rsBM.Delete
            ElseIf Trim(rsBM!cItemNo) = "" Then
                rsBM.Delete
            Else
                rsBM.MoveNext
            End If
        Else
            rsBM.MoveNext
        End If
    Loop

    If rsFG.RecordCount <> 0 Then rsFG.MoveFirst
    Do Until rsFG.EOF
        If rsFG.Status = (adRecNew) Or rsFG.Status = (adRecModified) Then
            If IsNull(rsFG!cItemNo) Then
                rsFG.Delete
            ElseIf Trim(rsFG!cItemNo) = "" Then
                rsFG.Delete
            Else
                rsFG.MoveNext
            End If
        Else
            rsFG.MoveNext
        End If
    Loop

    GetChild

    If rsFG.RecordCount < 1 Then
        MsgBox "Cannot save transaction without 'For Production' details.", vbExclamation, "ComUnion"
        MandatoryOK = False
        Exit Function
    End If

End Function

'Filter detail recordset to header's primary
Private Sub GetChild()
    rsBM.Filter = "cTranNo = '" & Trim(rsHeader!cTranNo) & "'"
    rsFG.Filter = "cTranNo = '" & Trim(rsHeader!cTranNo) & "'"
    rsSum.Filter = "cTranNo = '" & Trim(rsHeader!cTranNo) & "'"
End Sub

'Sets the form if record number is zero
Private Sub RSZero()
    sbRS.Panels(1) = "Record: 0/0"
    sbRS.Panels(2) = ""
    sbRS.Panels(4) = ""
    sbRS.Panels(5) = ""
    
    Set dtgSum.DataSource = Nothing
    Set dtgBM.DataSource = Nothing
    Set dtgFG.DataSource = Nothing
    dtgSum.Refresh
    dtgBM.Refresh
    dtgFG.Refresh
    
    Set FrmName = Me
    UnbindControls
    TextClearing
    FormLocking True
    
    If rsHeader.State = adStateOpen Then rsHeader.Close
    If rsSum.State = adStateOpen Then rsSum.Close
    If rsBM.State = adStateOpen Then rsBM.Close
    If rsFG.State = adStateOpen Then rsFG.Close
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
    
    txtTranNo.Locked = False
    txtTranNo.SetFocus
    
    Mode = Find
    
End Sub

Sub SearchObj(lEnable As Boolean)
    'dtbDate.Enabled = lEnable Disable by denz:2/17/2011
    cboType.Enabled = lEnable
End Sub

'Gets initital item values
Private Sub GetInitialItemValues(RefRS As Recordset)
    RefRS!cDesc = Trim(GetValueFrTable("cDesc", "ITEM", "cItemNo = '" & Trim(RefRS!cItemNo) & "'")) & ""
    RefRS!cUnit = Trim(GetValueFrTable("cUnit", "ITEM", "cItemNo = '" & Trim(RefRS!cItemNo) & "'")) & ""
    RefRS!nSRPrice = Trim(GetValueFrTable("nSRPrice", "ITEM", "cItemNo = '" & Trim(RefRS!cItemNo) & "'")) & ""
End Sub

Private Function GetSearchString() As String
On Error GoTo ErrorHandler
Dim sWhere As String

    GetSearchString = True

    If Trim$(txtTranNo.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cTranNo LIKE '" & Trim$(txtTranNo.Text) & "%'"
    End If

    If Trim$(dtbDate.Text) <> "__/__/____" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " dDate = '" & Trim$(dtbDate.Text) & "'"
    End If
    
    If Trim$(txtType.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cType LIKE '" & Trim$(txtType.Text) & "%'"
    End If
    
    If Trim$(txtRefNo.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cRefNo LIKE '" & Trim$(txtRefNo.Text) & "%'"
    End If
    
    GetSearchString = Trim$(sWhere)

    Exit Function
ErrorHandler:
    GetSearchString = "ERROR"
End Function

Private Sub txtType_Change()
    If Trim(txtType) <> "" Or txtType <> vbNullString Then
        cboType = Trim(txtType)
    Else
        cboType.ListIndex = -1
    End If
End Sub

'Form list to grid
Public Sub AddDetailsFromList()
    
    lAddDelete = True
    
    GetChild
    
    With frmARDRList.lvwList
        For i = 1 To .ListItems.Count
            If .ListItems(i).Checked = True Then
         
              Dim ii As Integer
              Dim iii As Integer
              If rsFG.RecordCount = 0 Then GoTo AddToList
              iii = 0
'              rsFG.MoveFirst
'              For ii = 0 To rsFG.RecordCount - 1
'                If Trim(.ListItems(i).Text) = rsFG!cItemNo Then iii = iii + 1
'                rsFG.MoveNext
'              Next
              
              If iii = 0 Then
AddToList:
            
            If GetValueFrTable("cType", "ITEM", "cItemNo = '" & Trim(.ListItems(i).Text) & "'") <> "Labor" Then
            
                rsFG.AddNew
                rsFG!cCompanyID = COID
                rsFG!cTranNo = Trim(rsHeader!cTranNo)
                rsHeader!cRefNo = Trim(frmARDRList.mRefPK)
                rsFG!cItemNo = Trim(.ListItems(i).Text)
                rsFG!cDesc = Trim(.ListItems(i).SubItems(1))
                rsFG!cUnit = Trim(.ListItems(i).SubItems(3))
                rsFG!nSRPrice = GetValueFrTable("nSRPrice", "ITEM", "cItemNo = '" & Trim(rsFG!cItemNo) & "'")
                rsFG!nQty = CDbl(.ListItems(i).SubItems(4))
                If Trim(cboType) = "From SO" Then rsFG!nRefIdentity = CDbl(.ListItems(i).SubItems(7))
                GetBillOfMaterials Trim(rsFG!cItemNo), rsFG
                
             ElseIf GetValueFrTable("cType", "ITEM", "cItemNo = '" & Trim(.ListItems(i).Text) & "'") = "Labor" Then
'                    OpenNewConnection connSum
'                    Set rsSum = Nothing
'                    Set rsSum = New ADODB.Recordset
'                    OpenRecordsetWithCN rsSum, "*", "PRODUCTION_S", connSum, "WHERE cTranNo = '" & Trim(rsHeader!cTranNo) & "' and cItemNoFG = '" & Trim(.ListItems(i).Text) & "' and nAddDelete <> '2'"
'                    Set dtgSum.DataSource = rsSum
        
                    rsSum.AddNew
                    rsSum!cCompanyID = COID
                    rsSum!cTranNo = Trim(rsHeader!cTranNo)
                    rsSum!cItemNo = Trim(.ListItems(i).Text)
                    rsSum!cDesc = Trim(.ListItems(i).SubItems(1))
                    rsSum!cItemNoFG = rsFG!cItemNo
                    If rsSum.RecordCount <> 0 Then rsSum.MoveLast
                    
                If rsHeader.State <> adStateOpen Then
                OpenNewConnection connSum
                OpenRecordsetWithCN rsSum, "*", "PRODUCTION_S", connSum, "WHERE 1 = 0"
                End If
                Set dtgSum.DataSource = rsSum
                rsSum!cItemNoFG = dtgFG.Columns(0).Value
                rsSum!nAddDelete = 1

                connSum.BeginTrans
                rsSum.UpdateBatch adAffectCurrent
                connSum.CommitTrans
                
                End If
                
                
              End If
            End If
        Next i
    End With

    GetChild

    lAddDelete = False
    
End Sub

'Get item components from item file
Sub GetBillOfMaterials(ProductID As String, RefRS As Recordset)
Dim rsDummy1 As New Recordset
Dim rsDummy2 As New Recordset

    
    
    sSQL = "SELECT * FROM ITEM_C WHERE cItemNo = '" & ProductID & "' AND cCompanyID = '" & COID & "'"
    Set rs = New Recordset
    
    rs.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
    
    Do Until rs.EOF
        Set rsDummy2 = rsFG.Clone
        rsDummy2.Filter = "cTranNo = '" & Trim(rsHeader!cTranNo) & "' AND cItemNo = '" & rs!cCompItemNo & "'"
        If rsDummy2.RecordCount < 1 Then
            rsBM.AddNew
            rsBM!cCompanyID = COID
            rsBM!cTranNo = Trim(rsHeader!cTranNo)
            rsBM!cItemNo = Trim(rs!cCompItemNo)
            rsBM!cDesc = Trim(rs!cCompItemDesc)
            rsBM!cUnit = GetValueFrTable("cUnit", "ITEM", "cItemNo = '" & Trim(rs!cCompItemNo) & "'")
            rsBM!nSRPrice = GetValueFrTable("nSRPrice", "ITEM", "cItemNo = '" & Trim(rs!cCompItemNo) & "'")
            rsBM!nQty = rs!nQty * RefRS!nQty
            
            sSQL = "SELECT ISNULL((nInitial - nOutgoing + nIncoming + nRetSales - nRetPur - nIssues + nBack - nProdOut + nProdIn + nAdjustment - nSampleDemo), 0) AS nBalance " & _
                    "FROM V_ProductBalanceInquiry_Module WHERE cItemNo = '" & Trim(rs!cCompItemNo) & "' AND cCompanyID = '" & COID & "'"
            
            Dim rsBal As Recordset
            Set rsBal = New Recordset
            rsBal.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
            
            If rsBal.RecordCount > 0 Then
                'If rsBal!nBalance <= 0 Then
                If rsBal!nBalance < rsBM!nQty Then
                    rsBM!cStatus = "No Stock"
                Else
                    rsBM!cStatus = "Available"
                End If
            Else
                rsBM!cStatus = "Available"
            End If
            rsBal.Close
            Set rsBal = Nothing
            
            If UCase(Trim(GetValueFrTable("cType", "ITEM", "cItemNo = '" & Trim(rs!cCompItemNo) & "'"))) = "BUY-OUT" Then
                If rsBM!cStatus = "No Stock" Then rsBM!cStatus = "Buy-out"
            End If
        End If
        
        rs.MoveNext
    Loop
    
    Set rsDummy1 = Nothing
    Set rsDummy2 = Nothing
    Set rs = Nothing
End Sub

Private Function AllowEdit() As Boolean
    AllowEdit = True
    
    'Cannot delete if transaction already has a receiving report
    If GetValueFrTable("cRefNo", "WRR_T A LEFT OUTER JOIN WRR B ON A.cWRRNo = B.cWRRNo", "A.cRefNo = '" & Trim(rsHeader!cTranNo) & "' AND A.cCompanyID = '" & COID & "' AND B.cType = 'PRODUCTION'", True) <> "" Then
        MsgBox "Cannot edit transaction with receiving report.", vbCritical + vbExclamation, "ComUnion"
        AllowEdit = False
        Exit Function
    'Cannot delete if transaction already has a delivery receipt
    ElseIf rsHeader!lRRReady = 1 Then
        MsgBox "Cannot edit transaction with delivery receipt.", vbCritical + vbExclamation, "ComUnion"
        AllowEdit = False
        Exit Function
    'Cannot delete if transaction already has a purchase request
    ElseIf GetValueFrTable("cRefNo", "REQUISITION", "cRefNo = '" & Trim(rsHeader!cTranNo) & "' AND cType = 'Production'") <> "" Then
        MsgBox "Cannot edit transaction with purchase request.", vbCritical + vbExclamation, "ComUnion"
        AllowEdit = False
        Exit Function
    End If
    
End Function

Private Function AllowDelete(sAction As String) As Boolean
    AllowDelete = True
    
    'Cannot delete if transaction already has a receiving report
    If GetValueFrTable("cRefNo", "WRR_T A LEFT OUTER JOIN WRR B ON A.cWRRNo = B.cWRRNo", "A.cRefNo = '" & Trim(rsHeader!cTranNo) & "' AND A.cCompanyID = '" & COID & "' AND B.cType = 'PRODUCTION'", True) <> "" Then
        MsgBox "Cannot " & sAction & " transaction with receiving report.", vbCritical + vbExclamation, "ComUnion"
        AllowDelete = False
        Exit Function
    'Cannot delete if transaction already has a delivery receipt
    ElseIf rsHeader!lRRReady = 1 Then
        MsgBox "Cannot " & sAction & " transaction with delivery receipt.", vbCritical + vbExclamation, "ComUnion"
        AllowDelete = False
        Exit Function
    'Cannot delete if transaction already has a purchase request
    ElseIf GetValueFrTable("cRefNo", "REQUISITION", "cRefNo = '" & Trim(rsHeader!cTranNo) & "' AND cType = 'Production'") <> "" Then
        MsgBox "Cannot " & sAction & " transaction with purchase request.", vbCritical + vbExclamation, "ComUnion"
        AllowDelete = False
        Exit Function
    End If

End Function

Sub GetStatus(ProductID As String)

On Error Resume Next
        
'    sSQL = "SELECT ISNULL((nInitial - nOutgoing + nIncoming + nRetSales - nRetPur - nIssues + nBack - nProdOut + nProdIn + nAdjustment - nSampleDemo), 0) AS nBalance " & _
'            "FROM V_ProductBalanceInquiry_Module WHERE cItemNo = '" & Trim(ProductID) & "' AND cCompanyID = '" & COID & "'"
'    Dim rsBal As Recordset
'    Set rsBal = New Recordset
'    rsBal.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
    
    Dim rsBal As New ADODB.Recordset
    ProductBalanceCommand rsBal, rsBM!cItemNo
    
    If rsBal.RecordCount > 0 Then
        'If rsBal!nBalance <= 0 Then
        If rsBal!nBalance < rsBM!nQty Then
            rsBM!cStatus = "No Stock"
        Else
            rsBM!cStatus = "Available"
        End If
    Else
        rsBM!cStatus = "Available"
    End If
    rsBal.Close
    Set rsBal = Nothing
    
    If UCase(Trim(GetValueFrTable("cType", "ITEM", "cItemNo = '" & Trim(ProductID) & "'"))) = "BUY-OUT" Then
        If rsBM!cStatus = "No Stock" Then rsBM!cStatus = "Buy-out"
    End If
        
End Sub

'Public Sub ShowForm(sTranNo As String)
'    If Mode = Find Then
'
'        OpenNewConnection connHeader
'        OpenNewConnection connSum
'        OpenNewConnection connBM
'        OpenNewConnection connFG
'
'        Set rsHeader = Nothing
'        Set rsSum = Nothing
'        Set rsBM = Nothing
'        Set rsFG = Nothing
'        Set rsHeader = New ADODB.Recordset
'        Set rsBM = New ADODB.Recordset
'        Set rsFG = New ADODB.Recordset
'
'        OpenRecordsetWithCN rsSum, "*", "PRODUCTION_S", connSum, "WHERE cTranNo = '" & Trim(sTranNo) & "'"
'        OpenRecordsetWithCN rsBM, "*", "PRODUCTION_BM", connBM, "WHERE cTranNo = '" & Trim(sTranNo) & "'"
'        OpenRecordsetWithCN rsFG, "*", "PRODUCTION_FG", connFG, "WHERE cTranNo = '" & Trim(sTranNo) & "'"
'        OpenRecordsetWithCN rsHeader, "*", "PRODUCTION", connHeader, "WHERE cTranNo = '" & Trim(sTranNo) & "'"
'
'        Set FrmName = Me
'        FormLocking True
'
'        If rsHeader.RecordCount = 0 Then
'            FormWaitHide
'            MsgBox "No matching record/s found.", vbInformation, "ComUnion Search"
'            RSZero
'            FormSearch True
'            SearchObj True
'            Mode = Find
'            Exit Sub
'        End If
'            SetDataSource
'            SetDataField
'            txtTranNo.BackColor = &HE0FFFF
'            Mode = Normal
'            oBar.BitEnabled Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , lACCancel, , , True, True, lACPrint, True
'
'    End If
'End Sub


Sub autoDR()
Dim rsDR As New ADODB.Recordset
Dim rsDR_T As New ADODB.Recordset
Dim rsTempFG As New ADODB.Recordset
Dim rsTempBM As New ADODB.Recordset
Dim tempGross As Double

Set rsTempFG = rsFG
Set rsTempBM = rsBM
tempGross = 0

    cString = "DR-" & Trim$(rsHeader!cTranNo)
    
    'FOR REVISION [DO NOT DELETE BECAUSE OF THE IDENTITY] ???????????
    cn.Execute ("DELETE DR_T WHERE cCompanyID = '" & COID & "' AND cDRNo = '" & Trim(cString) & "'")
    cn.Execute ("DELETE DR WHERE cCompanyID = '" & COID & "' AND cDRNo = '" & Trim(cString) & "'")
    
    'GetChild
    
    OpenRecordset rsDR, "*", "DR", "WHERE 1 = 0"
    OpenRecordset rsDR_T, "*", "DR_T", "WHERE 1 = 0"
    
    
    With rsDR
        .AddNew
        !cCompanyID = COID
        !cDRNo = Trim$(cString)
        !dDate = rsHeader!dDate
        !cType = "Production"
        !cDelCode = GetValueFrTable("cCode", "SO", "cSONo = '" & Trim(rsHeader!cRefNo) & "'")
        !cRemarks = "Auto DR from Production Order"
        '!nGross = GetValueFrTable("nGross", "SO", "cSONo = '" & Trim(rsHeader!cRefNo) & "'")
        !cdoctype = "DOC 2"
    End With

    rsTempFG.MoveFirst
    Do While Not rsTempFG.EOF
    
        rsTempBM.MoveFirst
        Do While Not rsTempBM.EOF
                
        With rsDR_T
            .AddNew
            !cCompanyID = COID
            !cDRNo = Trim$(cString)
            !cRefNo = rsHeader!cRefNo
            !nRefIdentity = rsTempBM!nIdentity
            !cWH = "MAIN"
            !cItemNo = rsTempBM!cItemNo
            !cDesc = rsTempBM!cDesc
            !cUnit = rsTempBM!cUnit
            !nQty = rsTempBM!nQty
            !nPrice = rsTempBM!nSRPrice
            !nAmount = rsTempBM!nQty * rsTempBM!nSRPrice
            !cCosting = "Average"
            tempGross = tempGross + (rsTempBM!nQty * rsTempBM!nSRPrice)
        End With
        
        rsTempBM.MoveNext
        Loop
        
    rsTempFG.MoveNext
    Loop
    
    rsDR!nGross = tempGross

    rsDR.UpdateBatch adAffectAll
    rsDR_T.UpdateBatch adAffectAll
    
    Set rsDR = Nothing
    Set rsDR_T = Nothing
    Set rsTempFG = Nothing
    Set rsTempBM = Nothing
  
End Sub


Sub autoWRR()

Dim rsWRR As New ADODB.Recordset
Dim rsWRR_T As New ADODB.Recordset
Dim rsTempFG As New ADODB.Recordset
Dim tempGross As Double

Set rsTempFG = rsFG
tempGross = 0

    cString = "RR-" & Trim$(rsHeader!cTranNo)
    
    'FOR REVISION [DO NOT DELETE BECAUSE OF THE IDENTITY] ???????????
    cn.Execute ("DELETE WRR_T WHERE cCompanyID = '" & COID & "' AND cWRRNo = '" & Trim(cString) & "'")
    cn.Execute ("DELETE WRR WHERE cCompanyID = '" & COID & "' AND cWRRNo = '" & Trim(cString) & "'")
    
    'GetChild
    
    OpenRecordset rsWRR, "*", "WRR", "WHERE 1 = 0"
    OpenRecordset rsWRR_T, "*", "WRR_T", "WHERE 1 = 0"
    
    
    With rsWRR
        .AddNew
        !cCompanyID = COID
        !cPCCode = "DEFAULT"
        !cWRRNo = Trim$(cString)
        !dDate = rsHeader!dDate
        !cType = "Customer"
        !cCode = GetValueFrTable("cCode", "SO", "cSONo = '" & Trim(rsHeader!cRefNo) & "'")
        !cName = GetValueFrTable("cName", "CLIENT_CUSTOMER", "cCode = '" & GetValueFrTable("cCode", "SO", "cSONo = '" & Trim(rsHeader!cRefNo) & "'") & "'")
        !cRemarks = "Auto RR from Production Order"
        '!nGross = GetValueFrTable("nGross", "SO", "cSONo = '" & Trim(rsHeader!cRefNo) & "'")
    End With

    rsTempFG.MoveFirst
    Do While Not rsTempFG.EOF
    
        With rsWRR_T
            .AddNew
            !cCompanyID = COID
            !cWRRNo = Trim$(cString)
            !cRefNo = rsHeader!cRefNo
            !nRefIdentity = rsTempFG!nIdentity
            !cWH = "MAIN"
            !cItemNo = rsTempFG!cItemNo
            !cDesc = rsTempFG!cDesc
            !cUnit = rsTempFG!cUnit
            !nQty = rsTempFG!nQty
            !nPrice = rsTempFG!nSRPrice
            !nAmount = rsTempFG!nQty * rsTempFG!nSRPrice
            tempGross = tempGross + (rsTempFG!nQty * rsTempFG!nSRPrice)
        End With
        
    rsTempFG.MoveNext
    Loop
    
    rsWRR!nGross = tempGross

    rsWRR.UpdateBatch adAffectAll
    rsWRR_T.UpdateBatch adAffectAll
    
    Set rsWRR = Nothing
    Set rsWRR_T = Nothing
    Set rsTempFG = Nothing
  
End Sub
